class_name PlayerStateBicycleKick
extends PlayerState

const BONUS_POWER := 2
const BALL_HEIGHT_MIN := 5
const BALL_HEIGHT_MAX := 25

func _enter_tree() -> void:
	animation_player.play("bicycle_kick")
	ball_detection_area.body_entered.connect(on_ball_entered.bind())
	
func on_ball_entered(connect_ball: Ball) -> void:
	if connect_ball.can_air_connect(BALL_HEIGHT_MIN, BALL_HEIGHT_MAX):
		var destination := player.get_target_position()
		var direction := ball.position.direction_to(destination)
		SoundPlayer.play(SoundPlayer.Sound.POWER_SHOT)
		connect_ball.shoot(direction * player.power * BONUS_POWER)
		
func on_animation_complete() -> void:
	state_transition(Player.State.RECOVERING)
